package com.ss.android.article.base.feature.update.activity;

import android.content.Context;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import com.ss.android.article.base.feature.update.a.UserInfo;
import java.lang.ref.WeakReference;

public class t extends ClickableSpan {
    public interface a {
        void a(UserInfo arg1, int arg2);
    }

    public static final class b extends LinkMovementMethod {
        public boolean a;
        private ClickableSpan b;
        private Object c;
        private int d;
        private Class e;

        public b(int arg1, Class arg2) {

            this.d = arg1;
            this.e = arg2;
        }

        private ClickableSpan a(TextView arg4, Spannable arg5, MotionEvent arg6) {
            ClickableSpan v0_3;
            int v0 = ((int)arg6.getX());
            int v1 = ((int)arg6.getY());
            v0 -= arg4.getTotalPaddingLeft();
            v1 -= arg4.getTotalPaddingTop();
            v0 += arg4.getScrollX();
            v1 += arg4.getScrollY();
            Layout v2 = arg4.getLayout();
            v0 = v2.getOffsetForHorizontal(v2.getLineForVertical(v1), ((float)v0));
            Object[] v0_1 = arg5.getSpans(v0, v0, this.e);
            ClickableSpan v1_1 = null;
            if(v0_1.length > 0) {
                v0_3 = (ClickableSpan) v0_1[0];
            }
            else {
                v0_3 = v1_1;
            }

            return v0_3;
        }

        public final boolean onTouchEvent(TextView arg5, Spannable arg6, MotionEvent arg7) {
            Object v2 = null;
            if(arg7.getAction() == 0) {
                this.b = this.a(arg5, arg6, arg7);
                if(this.b != null) {
                    if(this.c != null) {
                        arg6.removeSpan(this.c);
                    }

                    this.c = new BackgroundColorSpan(this.d);
                    arg6.setSpan(this.c, arg6.getSpanStart(this.b), arg6.getSpanEnd(this.b), 33);
                    Selection.setSelection(arg6, arg6.getSpanStart(this.b), arg6.getSpanEnd(this.b));
                    this.a = true;
                }
                else {
                    this.a = false;
                }
            }
            else {
                if(arg7.getAction() == 2) {
                    ClickableSpan v0 = this.a(arg5, arg6, arg7);
                    if(this.b == null) {
                        return this.a;
                    }

                    if(v0 == this.b) {
                        return this.a;
                    }

                    if(this.c != null) {
                        arg6.removeSpan(this.c);
                        this.c = v2;
                    }

                    this.b = ((ClickableSpan)v2);
                    Selection.removeSelection(arg6);
                    return this.a;
                }

                if(this.b != null) {
                    if(this.c != null) {
                        arg6.removeSpan(this.c);
                        this.c = v2;
                    }

                    super.onTouchEvent(arg5, arg6, arg7);
                }

                this.b = ((ClickableSpan)v2);
                Selection.removeSelection(arg6);
            }

            return this.a;
        }
    }

    private UserInfo a;
    private int b;
    private int c;
    private final WeakReference d;

    public t(Context arg3, a arg4, UserInfo arg5) {

        this.a = arg5;
        this.c = arg3.getResources().getColor(com.ss.android.article.browser.R.color.wq);
        arg3.getResources().getColor(com.ss.android.article.browser.R.color.fh);
        this.d = new WeakReference(arg4);
        this.b = 2;
    }

    public void onClick(View arg4) {
        Object v0 = this.d.get();
        if(v0 != null) {
            ((a)v0).a(this.a, this.b);
        }
    }

    public void updateDrawState(TextPaint arg2) {
        arg2.setColor(this.c);
        arg2.setUnderlineText(false);
    }
}

